package com.springboot.framework.dao.mapper;

import com.springboot.framework.dao.entity.Shop;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import tk.mybatis.mapper.common.Mapper;

import java.math.BigDecimal;
import java.util.List;

public interface ShopMapper extends Mapper<Shop> {

    @Select({"select " +
            "ROUND(6378.138*2*ASIN(SQRT(POW(SIN((#{latitude}*PI()/180-latitude*PI()/180)/2),2)+" +
            "COS(#{latitude}*PI()/180)*COS(latitude*PI()/180)*POW(SIN((#{longitude}*PI()/180-" +
            "longitude*PI()/180)/2),2)))*1000) AS distance , a.* " +
            "from shop as a " +
            "having distance <= #{distance} and a.status = 1 order by distance asc"})
    List<Shop> selectBydistance(@Param("longitude") BigDecimal longitude, @Param("latitude") BigDecimal latitude, @Param("distance") Integer distance);
}